<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%
String path = request.getContextPath();
%>
<script type="text/javascript">
var alreadyLevel = new Array();
function cardLevelEdit_submit(obj){
	if($("#sel_level").val()==""){
		alertMsg.error("请选择级别！");
		return false;
	}
	$("input[name='cardLevelVO.customerId']").val($("#customerId").val());
	return validateCallback(obj, navTabAjaxDone);
}
function changeCustomer(customerId){
	$.ajax({cache:false, url:"${pageContext.request.contextPath}/ajax/ajaxGetLevelByCustomer.do", type:"post", dataType:"json", data:{customerId:customerId}, success:function(json){showLevel(json,customerId);}});
}
function showLevel(json,customerId){
	var allLevel = new Array();
	for (var i = 1; i <= 20; i++) {
		allLevel.push(i);
	}
	for (var i in json) {
		if (customerId!="${cardLevelVO.customerVO.id}")
  			allLevel.splice($.inArray(parseInt(json[i].level),allLevel),1);
  		else if ("${cardLevelVO.level}"!=(json[i].level))
  			allLevel.splice($.inArray(parseInt(json[i].level),allLevel),1);
  	}
  	$("#sel_level").empty();
  	var oStr = "<option value='' selected='true'>请选择</option>";
  	for (var i in allLevel) {
  		oStr += "<option value='"+allLevel[i]+"'>"+allLevel[i]+"</option>";
  	}
  	$(oStr).appendTo($("#sel_level"));
  	if (customerId=="${cardLevelVO.customerVO.id}") {
  		$("#sel_level").find("option[value='']").remove();
  		$("#sel_level").find("option[value='${cardLevelVO.level}']").attr("selected", true);
  	}
}
function showLevelInit(already,selfLevel){
	var allLevel = new Array();
	for (var i = 1; i <= 20; i++) {
		allLevel.push(i);
	}
	for (var i in already) {
		if(already[i] != selfLevel)
  			allLevel.splice($.inArray(already[i],allLevel),1);
  	}
  	var oStr = "";
  	for (var i in allLevel) {
  		oStr += "<option value='"+allLevel[i]+"'"+(allLevel[i]==selfLevel?" selected='true'":"")+">"+allLevel[i]+"</option>";
  	}
  	$(oStr).appendTo($("#sel_level"));
}
</script>
	<div class="pageContent">
		<form method="post" action="<%=path %>/cardLevel/saveCardLevel.action" class="pageForm required-validate" onsubmit="return cardLevelEdit_submit(this);">
			<div class="pageFormContent" layoutH="56">
				<input name="cardLevelVO.id" type="hidden" value="<s:property value="cardLevelVO.id" />" />

				<p>
					<label>级别名：</label>
					<input name="cardLevelVO.levelName" value="<s:property value="cardLevelVO.levelName" />" class="required" type="text" size="30" alt="请输入级别名"/>
				</p>
				<p>
					<label>所属商家：</label>
					<input id="customerId" name="customerId" value="<s:property value="cardLevelVO.customerVO.id" />" type="hidden" size="30"/>
					<input name="cardLevelVO.customerVO.id" value="<s:property value="cardLevelVO.customerVO.id" />" type="hidden">
					<input id="customerName" name="customerName" value="<s:property value="cardLevelVO.customerVO.name" />" readonly>
					<c:if test="${SESSION_USER.customer==null}">
						<a class="btnLook" href="<%=path %>/customer/listCustomer.action?searchType=cardLevel" lookupGroup="">选择</a>
					</c:if>
				</p>
				<p>
					<label>可选级别：</label>
					<select name="cardLevelVO.level" id="sel_level">
					<s:iterator value="cardLevelList"><script type="text/javascript">alreadyLevel.push(parseInt("${level}"));</script></s:iterator>
					</select>
				</p>
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
					</li>
				</ul>
			</div>
		</form>
	</div>
<script type="text/javascript">showLevelInit(alreadyLevel,parseInt("${cardLevelVO.level}"));</script>